package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.AuthMapper;
import com.situ.springboot.pojo.entity.Auth;
import com.situ.springboot.service.IAuthService;
import com.situ.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthServiceImpl implements IAuthService {

    @Autowired
    private AuthMapper authMapper;

    //业务
    @Override
    public List<Auth> selectAll() {
        List<Auth> list = authMapper.selectAll();
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        authMapper.deleteById(id);
    }

    @Override
    public void add(Auth authType) {
        authMapper.add(authType);
    }

    @Override
    public Auth selectById(Integer id) {
        return authMapper.selectById(id);
    }

    @Override
    public void update(Auth authType) {
        authMapper.update(authType);
    }

    // totalCount:101
    // pageSize:10
    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<Auth> list = authMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = authMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<Auth>(list, totalPage, pageNo, pageSize);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        authMapper.deleteAll(ids);
    }

    @Override
    public List<Auth> selectByRoleId(Integer id) {
        return authMapper.selectByRoleId(id);
    }

}
